package com.llq.studentinfo;

import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;

import com.llq.studentinfo.Student;
import com.llq.studentinfo.StudentDirectory;

public class StudentDirectoryTest {
	private StudentDirectory dir;
	
	@Before
	public void init(){
		dir =new StudentDirectory();
	}

	@Test
	public void storeAndRetrieve(){
		final int numberOfStudents=10;
		
		for (int i = 0; i < numberOfStudents; i++) {
			addStudent(dir,i);
		}
		
		for (int i = 0; i < numberOfStudents; i++) {
			verifyStudentLookup(dir,i);
		}
	}

	private void verifyStudentLookup(StudentDirectory directory, int i) {
		String id=""+i;
		Student student=directory.findById(id);
		Assert.assertEquals(id, student.getLastName());
		Assert.assertEquals(id, student.getId());
		Assert.assertEquals(i, student.getCredits());
	}

	private void addStudent(StudentDirectory directory, int i) {
		String id=""+i;
		Student student=new Student(id);
		student.setId(id);
		student.addCredits(i);
		directory.add(student);
	}
}
